"""
Created on 2018/4/26 15:16 星期四
@author: Matt  zhuhan1401@126.com
Description: 学习scikit-learn中的 SVM算法应用
"""

from sklearn import svm
from sklearn.datasets import make_blobs
from commonTool.plotCurve import plot_hyperplane
from matplotlib import pyplot as plt

"""
# 生成一个有两个特征 包含两种类别的数据集
X, Y = make_blobs(n_samples=100, centers=2, random_state=0, cluster_std=0.3)
clf = svm.SVC(C=1.0, kernel='linear')
clf.fit(X, Y)
plt.figure(figsize=(12, 4), dpi=144)
plot_hyperplane(clf, X, Y, h=0.01, title='Maximum Margin Hyperplan')
plt.show()
"""
# 生成一个有两个特征 包含三种类别的数据集 分别构造4个SVM算法来拟合数据集
X, Y = make_blobs(n_samples=100, centers=3, random_state=0, cluster_std=0.8)
clf_linear = svm.SVC(c=1., kernel='linear')
clf_poly = svm.SVC(c=1., kernel='poly', degree=3)
clf_rbf = svm.SVC(c=1., kernel='rbf', gamma=0.5)
clf_rbf2 = svm.SVC(c=1., kernel='rbf', gamma=0.1)

plt.figure(figsize=(10, 10), dpi=144)
clfs = [clf_linear, clf_poly, clf_rbf, clf_rbf2]
titles = ['Linear Kernel',
          'Polynomial Kernel With Degree=3',
          'Gaussian Kernel with $\gamma=0.5$',
          'Gaussian Kernel with $\gamma=0.1$'
          ]
for clf, i in zip(clfs, range(len(clfs))):
    clf.fit(X, Y)
    plt.subplot(2, 2, i + 1)
    plot_hyperplane(clf, X, Y, title=titles[i])
plt.show()
print('asdfadf')